﻿Imports System.Text


Public Class ClsStrings


    ''' <summary>
    ''' Converts a string to alternate case (aLtErNaTeCaSe)
    ''' </summary>
    ''' <param name="sText">The string to convert.</param>
    ''' <param name="StartWithLowerCase">Start string with lowercase or uppercase
    ''' character.</param>
    ''' <param name="CalculateWord">Convert whole string (including spaces) or
    ''' convert word for word (not including spaces) to alternate case</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ToAlternateCase(ByVal sText As String, _
                                    ByVal StartWithLowerCase As Boolean, _
                                    Optional ByVal CalculateWord As Boolean = False) As String

        Dim Buffer As New StringBuilder
        Dim bLowerCase As Boolean = StartWithLowerCase
        Dim i As Integer

        If Not sText = "" Then

            Do Until i = sText.Length

                If CalculateWord = True AndAlso sText.Substring(i, 1) = " " Then
                    Buffer.Append(sText.Substring(i, 1))
                ElseIf bLowerCase = False Then
                    Buffer.Append(sText.Substring(i, 1).ToUpper)
                    bLowerCase = True
                ElseIf bLowerCase = True Then
                    Buffer.Append(sText.Substring(i, 1).ToLower)
                    bLowerCase = False
                End If

                i += 1

            Loop

        End If

        Return Buffer.ToString
        Buffer = Nothing

    End Function


End Class
